package com.etoak.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultVO<T> {

    public static final int SUCCESS_CODE = 200;

    public static final String SUCCESS_MESSAGE = "success";

    public static final int DEFAULT_FAILED_CODE = 500;

    public static final String DEFAULT_FAILED_MESSAGE = "系统异常！";

    public static final int NO_AUTH_CODE = 403;

    private Integer code;

    private String message;

    private T data;

    /**
     * 添加、更新、删除成功后调用(这种请求不需要返回data)
     */
    // 成功返回方法，不带数据
    public static <T> ResultVO<T> success() {
        return success(null);
    }

    // 成功返回方法，带数据
    public static <T> ResultVO<T> success(T data) {
        return new ResultVO<>(SUCCESS_CODE, SUCCESS_MESSAGE, data);
    }

    // 失败返回方法，使用默认失败信息
    public static <T> ResultVO<T> failed() {
        return failed(DEFAULT_FAILED_MESSAGE);
    }

    // 失败返回方法，带自定义失败信息
    public static <T> ResultVO<T> failed(String message) {
        return failed(DEFAULT_FAILED_CODE, message);
    }

    // 失败返回方法，带自定义失败码和失败信息
    public static <T> ResultVO<T> failed(int code, String message) {
        return new ResultVO<>(code, message, null);
    }

}
